package com.ymatou.iapi.fastturnover.testcase;

import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.FastTurnoverService;
import com.ymttest.database.model.fastturnover.TurnoverApply;
import com.ymttest.database.model.fastturnover.TurnoverApplyDetail;
import com.ymttest.database.sqlwapper.fastturnover.TurnoverApplyDetailWrapper;
import com.ymttest.database.sqlwapper.fastturnover.TurnoverApplyWrapper;

/**
 * 取消订单 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_onApplyDetailExportPayEvent {
	
	private static TurnoverApplyWrapper turnoverApplyWrapper = new TurnoverApplyWrapper();
	private static TurnoverApplyDetailWrapper turnoverApplyDetailWrapper = new TurnoverApplyDetailWrapper();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("导出支付结果成功通知");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult("onApplyDetailExportPayEvent");
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_onApplyDetailExportPayEvent_001() {
		Logger.start(true, "导出支付结果成功通知");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			
			FastTurnoverService.addTurnoverApply();
			
			String applyNo = turnoverApplyWrapper.selectBySellerIdAndPayStatus(20227567L, 0).getApply_no();
			String applyDetailNo = turnoverApplyDetailWrapper
					.selectBySellerIdAndApplyNo(20227567L, applyNo)
					.getApply_detail_no();
			
			FastTurnoverService.verifyTurnoverApply(Arrays.asList(applyNo));
			
			FastTurnoverService.onApplyDetailExportPayEvent(applyDetailNo);

			// 验证数据库结果
			TurnoverApply actualResult = turnoverApplyWrapper.selectByPrimaryKey(applyNo);
			
			Logger.verifyEquals(0, actualResult.getPay_status(),
					"验证Pay_status");
			Logger.verifyEquals(0, actualResult.getRepay_status(),
					"验证Repay_status");

			TurnoverApplyDetail actualTurnoverApplyDetail = turnoverApplyDetailWrapper.selectBySellerIdAndApplyNo(20227567L,
					applyNo);
			
			Logger.verifyEquals(5, actualTurnoverApplyDetail.getStatus(),
					"验证status");
			
			// 将申请单置为废弃
			turnoverApplyWrapper.updateToFinishByApplyNo(applyNo);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}

